import os
import logging
from datetime import datetime
from ..utils import utils

class Logs:
    def __init__(self):
        self.logger = logging.getLogger()
        self.logger.setLevel(logging.DEBUG)

        formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(module)s - %(message)s')

        ch = logging.StreamHandler()
        ch.setLevel(logging.DEBUG)
        ch.setFormatter(formatter)
        self.logger.addHandler(ch)

        log_name = 'mcutools_%s.log'%(datetime.now().strftime('%m_%d_%H_%M_%S'))

        out_file = os.path.join(utils.project_path(), "output", "log", log_name)
        os.makedirs(os.path.dirname(out_file), exist_ok = True)

        fh = logging.FileHandler(out_file, encoding='utf-8')
        fh.setLevel(logging.DEBUG)
        fh.setFormatter(formatter)
        self.logger.addHandler(fh)

    def debug(self, *args):
        self.logger.debug(' '.join([str(arg) for arg in args]))

    def info(self, *args):
        self.logger.info(' '.join([str(arg) for arg in args]))

    def warning(self, *args):
        self.logger.warning(' '.join([str(arg) for arg in args]))

    def error(self, *args):
        self.logger.error(' '.join([str(arg) for arg in args]))

    def critical(self, *args):
        self.logger.critical(' '.join([str(arg) for arg in args]))
